<?php
namespace app\admin\controller;

use app\common\model\DistributeUser as DistributeUserModel;
use app\common\model\Exhibition as ExhibitionModel;
use app\common\model\Order as OrderModel;
use app\admin\tool\Parser;
use think\Db;
use think\Request;


/**
 * 这个类应该是要作废了 功能已经分散到其他类了
 * Class Personal
 * @package app\admin\controller
 */
class Personal extends Base{

    /**
     * 客服的用户
     * 显示最新的活动 分配给客服的用户 指的是那些已经报名的
     * 我的用户
     */
    public function myUsers(){

        $this->data['title'] = '我的用户';
        $this->data['column'] = $this->column();

        $exhibition = ExhibitionModel::where('exhibition_time','>',time())->where('state',0)->order('exhibition_time desc')->find();

        //找到该客服的报名的信息
        $model = Db::table("distribute_user")->where("du.state = 0")->where('du.admin_id = '.$this->admin->id)->where('e.exhibition_id = '.$exhibition['id'])->alias('du')->join('enroll e','du.user_id = e.user_id')->paginate(10);

        $this->data['model'] = $model;
        $this->data['parser'] = new Parser();

        return view("",$this->data);
    }


    /**
     * 我的用户的订单列表
     * @param Request $request
     * @throws
     * @return mixed
     */
    public function orderList(Request $request){
        $user_id = $request -> param('user_id');
        $exhibition = ExhibitionModel::where('exhibition_time','>',time())->where('state',0)->order('exhibition_time desc')->find();
        $order_list = OrderModel::where(['user_id'=>$user_id,'exhibition_id'=>$exhibition['id']])->paginate(10);

        $this->data['model'] = $order_list;
        $this->data['column'] = [
            'order_num'=>['name'=>'订单编号','fun'=>'text','options'=>''],
            'total_price'=>['name'=>'总金额','fun'=>'text','options'=>''],
            'total_salary'=>['name'=>'总佣金','fun'=>'text','options'=>''],
            'cellphone' =>['name'=>'联系人手机','fun'=>'text','options'=>''],
            'add_time'=>['name'=>'添加时间','fun'=>'datetime','options'=>['format'=>'Y-m-d H:i']],
            'update_time'=>['name'=>'更新时间','fun'=>'text','options'=>[]],
        ];
        $this->data['title'] = '订单列表';
        $this->data['parser'] = new Parser();

        return view('',$this->data);
    }

    protected function column(){
        return [
            'real_name'=>['name'=>'用户姓名','fun'=>'text','options'=>''],
            'mobile'=>['name'=>'用户手机号码','fun'=>'text','options'=>''],
            'province_name'=>['name'=>'省','fun'=>'text','options'=>''],
            'city_name'=>['name'=>'市','fun'=>'text','options'=>''],
            'district_name'=>['name'=>'区','fun'=>'text','options'=>''],
        ];
    }

}